package datastructures
{
	public class BinaryTree
	{
		/*====================
		 * Variables
		 *====================
		 */
		private var _value:Object;
		public function get value():Object{
			return this._value;
		}
		
		private var _parent:BinaryTree = null;
		public function get parent():BinaryTree{
			return this._parent;
		}
		
		private var _left:BinaryTree = null;
		public function get left():BinaryTree{
			return this._left;
		}
		
		private var _right:BinaryTree = null;
		public function get right():BinaryTree{
			return this._right;
		}
		
		/*====================
		 * Constructor
		 *====================
		 */
		public function BinaryTree()
		{
		}
		
		/*====================
		 * Methods
		 *====================
		 */
		public function get next():BinaryTree{
			if(this._left != null){
				return this._left.getMin();
			}
			else if(this._parent == null){
				return null;
			}
			else if(this._parent._left == this){
				return this._parent;
			}
			else if(this._parent._right != null){
				return this._parent._right.getMin();
			}
			else{
				return null;
			}
		}
		
		public function get prev():BinaryTree{
			if(this._left != null){
				return this._left.getMin();
			}
			else if(this._parent == null){
				return null;
			}
			else if(this._parent._right == this){
				return this._parent;
			}
			return null;
		}
		
		public function getMin():BinaryTree{
			var cur:BinaryTree = this;
			while(cur._right != null){
				cur = cur._right;
			}
			return cur;
		}
		
		public function getMax():BinaryTree{
			var cur:BinaryTree = this;
			while(cur._left != null){
				cur = cur._left;
			}
			return cur;
		}
		

	}
}